package com.base.action;

import com.command.ChatMessageHandler;
import com.framework.view.ResultDatas;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.socket.TextMessage;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 */
@Controller
@RequestMapping("/web/socket/cache")
public class WebsocketController {
    @Resource(name = "chatMessageHandler")
    ChatMessageHandler chatMessageHandler;

    @RequestMapping("/websocket/send")
    @ResponseBody
    public Object send(HttpServletRequest request) {
        ResultDatas resultDatas = new ResultDatas();
        try {
            String username = request.getParameter("username");
//        chatMessageHandler.sendMessageToUsers(username, new TextMessage("你好，测试！！！！"));
            chatMessageHandler.sendMessageToUsers(new TextMessage("您有新的订单,请及时处理!"));
            resultDatas=new ResultDatas(0,"信息发送成功",null);
        }catch (Exception e){
            resultDatas=new ResultDatas(1,"信息发送失败",null);
            e.printStackTrace();
        }
        return resultDatas;
    }
}
